import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/Main'    //重定向
  },
  {
    // 初始页
    path: '/Main',
    name: 'main',
    redirect: "homeView",
    component: () => import(/* webpackChunkName: "about" */ '../views/Main.vue'),
    children: [
      {
        // 首页
        path: '/homeView',
        name: 'homeView',
        component: () => import('../views/HomeView.vue'),
        // meta: { isAuth: true, },
      },
      {
        // 竞标列表
        path: '/aboutView',
        name: 'aboutView',
        component: () => import('../views/AboutView.vue')
      },
      {
        // 竞价结果公示
        path: '/biddingPublicityView',
        name: 'biddingPublicityView',
        component: () => import('../views/biddingPublicityView.vue')
      },
      {
        // 竞标详情
        path: '/tenderView',
        name: 'tenderView',
        component: () => import('../views/TenderView.vue')
      },
    ]
  },
  {
    // 注册页
    path: '/userEnrollView',
    name: 'userEnrollView',
    component: () => import('../views/UserEnrollView.vue')
  },
  {
    // 个人中心页面
    path: '/PersonalPageView',
    name: 'PersonalPageView',
    component: () => import('../views/PersonalPageView.vue')
  },
  {
    // 测试页面
    path: '/test',
    name: 'test',
    component: () => import('../views/test.vue')
  }
]


const router = new VueRouter({
  // 取消路由路径的#
  // mode: 'history',
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 在session中存入当前页面的页面名字
  sessionStorage.setItem('userPageStatus', to.path)
  console.log(from.path,"->",to.path)
  next()
})

/* 路由拦截器 路由跳转后的操作 */
router.afterEach(to => {
  // 在这里执行路由跳转成功后所进行的操作
})


export default router

